﻿using System;
using System.Collections.Specialized;
using System.ComponentModel;

namespace Sidvall.Business
{
    public class ChildChangedEventArgs : EventArgs
    {
        #region Public Members

        public object ChildObject { get; private set; }
        public PropertyChangedEventArgs PropertyChangedArgs { get; private set; }
        public NotifyCollectionChangedEventArgs CollectionChangedArgs { get; private set; }

        #region GetChildObjectName

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
        public string GetChildObjectName()
        {
            if (this.ChildObject == null)
                return string.Empty;
            return this.ChildObject.GetType().Name;
        }

        #endregion
        #region GetPropertyName

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
        public string GetPropertyName()
        {
            if (string.IsNullOrWhiteSpace(this.PropertyChangedArgs?.PropertyName))
                return string.Empty;
            return this.PropertyChangedArgs.PropertyName;
        }

        #endregion
        #region GetPropertyFullName

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
        public string GetPropertyFullName()
        {
            if (this.ChildObject == null)
                return string.Empty;
            if (string.IsNullOrWhiteSpace(this.PropertyChangedArgs?.PropertyName))
                return string.Empty;
            return this.ChildObject.GetType().Name + "." + this.PropertyChangedArgs.PropertyName;
        }

        #endregion

        #endregion
        #region Constructors

        public ChildChangedEventArgs(NotifyCollectionChangedEventArgs listArgs)
        {
            if (listArgs == null)
                throw new System.ArgumentNullException(nameof(listArgs));
            this.CollectionChangedArgs = listArgs;
        }
        public ChildChangedEventArgs(object child, PropertyChangedEventArgs propertyArgs)
        {
            if (child == null)
                throw new System.ArgumentNullException(nameof(child));
            if (propertyArgs == null)
                throw new System.ArgumentNullException(nameof(propertyArgs));
            this.ChildObject = child;
            this.PropertyChangedArgs = propertyArgs;
        }
        public ChildChangedEventArgs(object child, NotifyCollectionChangedEventArgs listArgs)
        {
            if (child == null)
                throw new System.ArgumentNullException(nameof(child));
            if (listArgs == null)
                throw new System.ArgumentNullException(nameof(listArgs));
            this.ChildObject = child;
            this.CollectionChangedArgs = listArgs;
        }

        #endregion
    }
}
